/**
 * 将结构组织树转成数组
 * @param {Array} treeDataList 树结构的list
 * @param {String} childProp 孩子的属性名
 * @param {function} filterFn 过滤的数据的函数
 * @returns {*[]}
 */
const convertTreeToArray = (treeDataList, childProp = 'children', filterFn = () => true) => {
    let rel = [];

    if (!treeDataList || treeDataList.length === 0 || !Array.isArray(treeDataList)) {
        return rel;
    }

    treeDataList.forEach((treeData, index) => {
        if (filterFn(treeData, index)) {
            rel.push(treeData);
        }
        if (childProp) {
            rel = [...rel, ...convertTreeToArray(treeData[childProp])];
        }
    });

    return rel;
};

export { convertTreeToArray };
